﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="false" CodeFile="recPaymentVerification.aspx.cs" Inherits="SIPO.Web.Lists.Transaction.recPaymentVerification" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    <div>
        <button id="btnVerify" type="button" onclick="verify();">
            Verifikasi</button>
            <asp:HiddenField ID="RandomList" runat="server" />
    </div>
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog" title="Default dialog">
    </div>
    <script type="text/javascript">
        $("#btnVerify").button({ icons: { primary: "ui-icon-plus"} });
        function verify() {
            //alert('MASUK');
            //var objrecBilling = new Object();
            //objrecBilling.BillingNo = encodeURIComponent(selText);
            //jsonData = JSON.stringify($("#<%=RandomList.ClientID%>").val());

            var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recPaymentVerificationhandler.ashx") %>';

            $.ajax({
                type: 'POST',
                url: handlerUrl + "?method=verify&param=" + $("#<%=RandomList.ClientID%>").val(),
                contentType: 'application/json',
                dataType: 'json',
                //data: jsonData,
                success: function (data) {
                    if (data.IsSuccess) {
                        //alert(data);

                        //                        parent.$('#dialog').dialog('close');
                        //                         setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);
                        //                        alert(data.Message);
                        //                        window.open('../../reports/Transaction/rptInvoice.aspx?InvoiceNo=' + data.Data, 'popUpWindow', 'height=400,width=800,left=300,top=200,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no, status=yes');
                    }
                    else {
                        //alert(data.Message);
                    }
                },
                error: function (response) {
                    var r = JSON.parse(response.responseText);
                    alert("Error Message: " + r.Message);
                }
            });

            setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);
            $("#table").jqGrid('setGridParam', { url: handlerUrl + '?method=getdata' }).trigger('reloadGrid');

            return false;
        }
    </script>
    <script type="text/javascript">
        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recPaymentVerificationhandler.ashx") %>';
        var listId = new Array();
        function removeA(arr) {
            var what, a = arguments, L = a.length, ax;
            while (L > 1 && arr.length) {
                what = a[--L];
                while ((ax = arr.indexOf(what)) !== -1) {
                    arr.splice(ax, 1);
                }
            }
            return arr;
        }

        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',
            colNames: ['Nama Perusahaan', 'Sektor', 'No Invoice', 'Jumlah Tagihan', 'ID Transaksi', 'Jumlah Pembayaran', 'Tgl Jatuh Tempo'],
            colModel: [
                    { name: 'NamaPerusahaan', index: 'NamaPerusahaan', width: 60 },
                    { name: 'NamaSector', index: 'NamaSector', width: 60 },
                    { name: 'NoInvoice', index: 'NoInvoice', align: 'center', width: 0 },
                    { name: 'JumlahTagihan', index: 'JumlahTagihan', formatter: 'currency',
                        align: 'right', formatoptions: { decimalSeparator: ".", thousandsSeparator: ",", decimalPlaces: 2 },
                        width: 0
                    },
                    { name: 'IDTransaksi', index: 'IDTransaksi', align: 'center', width: 0 },
                    { name: 'JumlahPembayaran', index: 'JumlahPembayaran', formatter: 'currency',
                        align: 'right', formatoptions: { decimalSeparator: ".", thousandsSeparator: ",", decimalPlaces: 2 },
                        width: 0
                    },
                    { name: 'TanggalJatuhTempo', index: 'TanggalJatuhTempo', align: 'center', width: 0,
                        formatter: 'date', formatoptions: { newformat: 'd M Y' }
                    }
           	],
            rowNum: 10,
            id: 'RestructurID',
            rownumbers: true,
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'NamaPerusahaan',
            sortorder: "asc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 1250,
            height: '100%',
            caption: 'Verifikasi Pembayaran',
            ajaxGridOptions: { cache: false },

            onSelectRow: function (id, status) {
                //listId = $("#<%=RandomList.ClientID%>").val();
                //alert('a  : ' + listId);
                var rowData = jQuery(this).getRowData(id);
                IDTransaksi = rowData['NoInvoice'];
                //alert("value of :  " + listId);
                //alert(IDTransaksi);
                if (listId.valueOf(IDTransaksi) != IDTransaksi && status == true) {
                    listId.push(IDTransaksi);
                    //alert(listId);
                }
                else {
                    //alert(listId);
                    removeA(listId, IDTransaksi);
                    //alert(listId);
                }
                //alert("value after :  " + listId);

                $("#<%=RandomList.ClientID%>").val(listId.toString());


                rowChecked = 1;
                currentrow = id;
            },

            onSelectAll: function (ids, status) {

                if (status) {
                    listId = [];
                    for (var i = 0; i < ids.length; i++) {
                        var rowData = jQuery(this).getRowData(ids[i]);
                        IDTransaksi = rowData['NoInvoice'];
                        listId.push(IDTransaksi);
                    }
                } else {
                    listId = [];
                }

                //                //listId = $("#<%=RandomList.ClientID%>").val();
                //                //alert('b'+listId);
                //                //alert(ids.toString());
                //                var yoga = ids.toString();
                //                //alert(yoga);
                //                var res = yoga.split(",");

                //                for (var i = 0; i < res.length; i++) {
                //                    //alert(res[i]);
                //                    var rowData = jQuery(this).getRowData(res[i]);
                //                    IDTransaksi = rowData['NoInvoice'];
                //                    //alert(IDTransaksi);
                //                    if (status == true) {
                //                        listId.push(IDTransaksi);
                //                    }
                //                    else {
                //                        removeA(listId, IDTransaksi);
                //                        //listId.splice(IDTransaksi);
                //                    }
                //                }
                //alert(listId);
                $("#<%=RandomList.ClientID%>").val(listId.toString());
               // alert("SEMUA : " + $("#<%=RandomList.ClientID%>").val());
            }
        });

        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true });
    </script>
</asp:Content>

